function [betasf,gammaf,cf]=startvalVlstar(y,x,q,c)

bestmse=999999;

T=size(y,1);
N=size(x,2);

maxgamma  = log(10000);
mingamma  = log(0.001);
rategamma = 0.01;

for newgamma=mingamma:rategamma:maxgamma
    
    fX  = 1./(1+exp(-exp(newgamma)/std(q)*(q-c)));
      
    rec = 1-fX;

    betas=[];
    e=[];
    for i=1:N;

        y_i=y(:,i);

        x_i=[ones(T,1) x(:,i)];

        x_i=[x_i.*(rec*ones(1,2)) x_i.*(1-(rec(:,1)*ones(1,2)))];

        betas_i=x_i\y_i;

        betas=[ betas; betas_i ];

        e_i=y_i-x_i*betas_i;
        e=[ e e_i ];

    end

    eVector=reshape(e,[T*N,1]); 
    
    mse   = sum(sum(eVector.^2,2),1)/T;
    
    if mse<bestmse
        bestmse = mse;
        gammaf   = newgamma;
        cf       = c;
        betasf   = betas;
    end

end
